package com.xiaochun.jiankangapp.utils

import android.content.Context
import android.provider.Settings
import com.xiaochun.jiankangapp.base.AppContext

object SPUtils {
    @JvmStatic
    private val sp =
        AppContext.globalContext().getSharedPreferences("app_setting", Context.MODE_PRIVATE)

    fun setToken(token: String?) {
        sp.edit().putString("user_token", token).apply()
    }

    fun getToken(): String? {
        return sp.getString("user_token", null)
    }

    fun getInt(key: String, defaultValue: Int = -1): Int {
        return sp.getInt(key, defaultValue)
    }

    fun setInt(key: String, value: Int) {
        sp.edit().putInt(key, value).apply()
    }

    /**
     * AndroidId标识符获取
     *
     * @return
     */
    fun getAndroidID(): String {
        val mContext: Context = AppContext.globalContext()
        try {
            return Settings.Secure.getString(mContext.contentResolver, Settings.Secure.ANDROID_ID)
        } catch (ex: Exception) {
            ex.printStackTrace()
            return ""
        }
    }
}